package com.itqf.service.impl;

import com.itqf.bean.DtsGoodsExample;
import com.itqf.mapper.DtsGoodsMapper;
import com.itqf.service.DtsGoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * projectName: gp_manage
 *
 * @author: 赵伟风
 * time: 2021/8/18 17:28
 * description:
 */
@Service
public class DtsGoodsServiceImpl implements DtsGoodsService {

    @Autowired
    private DtsGoodsMapper dtsGoodsMapper;

    /**
     * 查询商品数量，查询全部
     *
     * @return
     */
    @Override
    public Long findGoodsTotal() {

        //上架  没有逻辑删除
        DtsGoodsExample dtsGoodsExample =  new DtsGoodsExample();
        DtsGoodsExample.Criteria criteria = dtsGoodsExample.createCriteria();

        criteria.andIsOnSaleEqualTo(true);
        criteria.andDeletedEqualTo(false);

        long goodsTotal = dtsGoodsMapper.countByExample(dtsGoodsExample);

        return goodsTotal;
    }

    /**
     * 查询品牌的商品数量
     *
     * @param brandIds
     * @return
     */
    @Override
    public Long findGoodsTotal(List<Integer> brandIds) {

        //上架  没有逻辑删除  品牌
        DtsGoodsExample dtsGoodsExample =  new DtsGoodsExample();
        DtsGoodsExample.Criteria criteria = dtsGoodsExample.createCriteria();

        criteria.andIsOnSaleEqualTo(true);
        criteria.andDeletedEqualTo(false);
        criteria.andBrandIdIn(brandIds);

        long goodsTotal = dtsGoodsMapper.countByExample(dtsGoodsExample);

        return goodsTotal;
    }
}
